package de.hsb.ai.devil.ui.components;

import jade.core.AID;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;

import javax.swing.JDialog;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class StartGameDialog extends JDialog {
	private JButton jButton1;
	private JPanel versusPanel;
	private JButton btn_switchPlayer;
	private JLabel lbl_playerOne;
	private JButton jButton2;
	private JLabel lbl_playerTwo;
	private JLabel lbl_versus;
	
	private Boolean switched = false;
	private ActionListener actionListener;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	
	public StartGameDialog(AID player1, AID player2) {
		super();
		initGUI();
		lbl_playerOne.setText(player1.getLocalName());
		lbl_playerTwo.setText(player2.getLocalName());
	}
	
	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(400, 165));
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			pack();
			this.setSize(400, 165);
			getContentPane().setLayout(null);
			setVisible(true);
			setModal(true);
			{
				versusPanel = new JPanel();
				versusPanel.setMinimumSize(new Dimension(400, 50));
				versusPanel.setPreferredSize(new java.awt.Dimension(400, 35));
				versusPanel.setSize(-1, -1);

				versusPanel.setLayout(null);

				{
					//PLAYER ONE
					lbl_playerOne = new JLabel("PlayerOne", null, JLabel.RIGHT);
					lbl_playerOne.setMinimumSize(new Dimension(150, 50));
					versusPanel.add(lbl_playerOne);
					lbl_playerOne.setBounds(0, 9, 150, 50);
					lbl_playerOne.setFont(new java.awt.Font("Dialog",1,16));
				}
				{
					//VERSUS LB
					lbl_versus = new JLabel("VS.", null, JLabel.CENTER);
					lbl_versus.setMinimumSize(new Dimension(100, 50));
					lbl_versus.setHorizontalTextPosition(JLabel.CENTER);
					versusPanel.add(lbl_versus);
					lbl_versus.setBounds(150, 9, 100, 50);
				}
				{
					//PLAYER ONE
					lbl_playerTwo = new JLabel("PlayerTwo", null, JLabel.LEFT);
					lbl_playerTwo.setMinimumSize(new Dimension(150, 50));
					lbl_playerTwo.setAlignmentX(LEFT_ALIGNMENT);
					versusPanel.add(lbl_playerTwo);
					lbl_playerTwo.setBounds(250, 9, 150, 50);
					lbl_playerTwo.setFont(new java.awt.Font("Dialog",1,14));
				}
				
				getContentPane().add(versusPanel);
				versusPanel.setBounds(0, 0, 400, 50);

			}
			{
				btn_switchPlayer = new JButton();
				getContentPane().add(btn_switchPlayer);
				btn_switchPlayer.setText("Switch");
				btn_switchPlayer.setBounds(173, 70, 50, 22);
				
				btn_switchPlayer.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						String p1 = lbl_playerOne.getText();
						String p2 = lbl_playerTwo.getText();
						lbl_playerOne.setText(p2);
						lbl_playerTwo.setText(p1);
						
						switched = !switched;
					}
				});

			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Play");
				jButton1.setBounds(173, 103, 50, 22);
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						actionListener.actionPerformed(e);
						dispose();
					}
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void setStartListener(ActionListener listener){
		actionListener = listener; 
	}
	
	public boolean isSwitched(){
		return switched;
	}

}
